<?PHP
require_once("./include/membersite_config.php");

if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("login.php");
    exit;
}
$answer = $_POST['rr'];
$ontime = $_POST['ontime'];

$totalCorrect = 0;
$totalCorrect = $_SESSION['total_correct'];
$trivia = false;


if ($answer =="" || $answer == " ")
	$answer = 0;

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<title>Grade Results</title>
	<?php include 'imports.php'?>
</head>
<body>
<?php include 'navbar.php'; ?>
<div class="container">
		<div class="row clearfix">
	<div id="page-wrap" class="well">
		<h4>Respuesta a la pregunta = <?php echo $_SESSION['current_question']?> :</h4>
        <?php	
			$retry = $_SESSION['question_retry'];

 			if( $answer == $_SESSION['question_correct'] ){
				if ($retry <= 1 && $ontime==1)
				{
					$grade = 5;	
					$message = "dentro del tiempo otorgado " ;
				}
				else
				{
					$grade = 2;
					$message = "durante el tiempo extendido" ;
				}
					
				$totalCorrect++;
				$_SESSION['total_correct'] = $totalCorrect;
				echo "<div class='alert alert-success'>
						<strong>Respuesta Correcta!</strong>
						<br />
						Usted obtuvo " . $grade . " ptos  por responder " . $message ."						
					  </div>";
					 
			}else{
				$grade = 0;
				echo "<div class='alert alert-danger'>
						<strong>Respuesta Incorrecta</strong>
						<br />
					  </div>";
				//, Seleccionada:".$answer." Correcta: <strong>".$_SESSION['question_correct'] ."</strong> </div>";
			}	

			if(!$fgmembersite->Answer($_SESSION['userid'], $_SESSION['current_question'], $answer, $grade, $retry))
			{
				echo "<div class='alert alert-danger'>Error actualizando la respuesta:". $fgmembersite->GetErrorMessage()."</div>";
			}
			
			echo '<a class="btn btn-success" href="trivia.php" >Siguiente pregunta</a>';
			//$fgmembersite->RedirectToURL("trivia.php");
			//echo "<div id='results'  class='alert alert-info'> $totalCorrect / 5 correct</div>";
        ?>
	</div>
	
    <!--
	<script type="text/javascript">
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	</script>
	<script type="text/javascript">
	var pageTracker = _gat._getTracker("UA-68528-29");
	pageTracker._initData();
	pageTracker._trackPageview();
	</script>
	-->
</div>
</div>
</body>

</html>